<?php
	/**
	 +=========================================================
	 * 友情链接管理模块
	 * FlinkAction
	 +=========================================================
	 * @copyright © 2011 focalthinker.com All rights reserved.
	 * @author NickDraw(零度温柔) webmaster@206c.net
	 * @license http://www.206c.com/license
	 +=========================================================
	 */
	class FlinkAction extends CommonAction{
		/*public function _before_add()
		{
			$this->getCategoryOption('flink');
		}
		
		public function _before_edit(){
			$this->getCategoryOption('flink', $_GET['cid']);
		}
		*/
		public function _after_insert(){
			D('flink_type')->where("id='".$_POST['cid']."'")->setInc('count');
		}
		
		public function _after_delete(){
			D('flink_type')->where("id='".$_GET['cid']."'")->setDec('count');
		}
		
		
		public function typelist(){
            $model = M('flink_type');
			$list = $model->select();
			$this->assign('list',$list);
            Cookie::set ( '_currentUrl_', __SELF__ );
            $this->display();
        }
        
		public function addtype(){
			$this->display();
		}
		
		public function insertlinktype(){
			$model = D('flink_type');
			if ($model->add($_POST)){
				$this->assign ( 'jumpUrl', Cookie::get ( '_currentUrl_' ) );
				$this->success ('新增成功!');
			}else{
				$this->error ('新增失败!');
			}
		}
        
        public function updatelinktype(){
            $model = D('flink_type');
            if ($model->where("id='".$_POST['id']."'")->save($_POST)){
                $this->assign ( 'jumpUrl', Cookie::get ( '_currentUrl_' ) );
                $this->success ('新增成功!');
            }else{
                $this->error ('新增失败!');
            }
        }
        
        public function edittype(){
            $model = M('flink_type');
            $list = $model->where("id='".$_GET['id']."'")->find();
            $this->assign("vo",$list);
            $this->display("edit_type");
        }
		
		//获得链接分类
		public function _before_add(){
			self::getlinkCategory();
		}
		
		public function _before_edit(){
			self::getlinkCategory();
		}
		
		private function getlinkCategory(){
			$model = M('flink_type');
			$list = $model->where("status=1")->select();
			$this->assign('list',$list);
		}
	}
